import 'dart:convert';

import 'package:ls_work/a_yyt/models/pending_entity.dart';

class WaitingRighrEntity {
  final int? total;
  List<WaitingRighInfo>? rows;

  WaitingRighrEntity({this.rows, this.total});

  factory WaitingRighrEntity.fromJson(Map<String, dynamic> json) {
    final originList = json['rows'] as List?;
    List<WaitingRighInfo> protocolList =
        (originList??[]).map((value) => WaitingRighInfo.fromJson(value)).toList();
    return WaitingRighrEntity(rows: protocolList, total: json['total']);
  }
}

class WaitingRighInfo {
  String? name;
  String? elderName;
  int? age;
  int? id;
  int? bizType;
  int? bizId;
  int? resultMode; // == 0 时直接完成执行
  int? customerId;
  String? sexName;
  String? branchName;
  String? buildingNo;
  String? floorNo;
  String? roomNo;
  String? statusSecondName;
  String? nurseLevelName;
  BizParams? bizParams;
  String? resultUnit;

  DateTime? dateTime;
  String? itemRemark;
  bool? isSelected;

  WaitingRighInfo({
    this.resultMode,
    this.name,
    this.elderName,
    this.age,
    this.id,
    this.bizId,
    this.customerId,
    this.sexName,
    this.branchName,
    this.buildingNo,
    this.floorNo,
    this.roomNo,
    this.statusSecondName,
    this.nurseLevelName,
    this.bizParams,
    this.bizType,
    this.dateTime,
    this.itemRemark,
    this.isSelected,
    this.resultUnit,
  });

  factory WaitingRighInfo.fromJson(Map<String, dynamic> json) {
    return WaitingRighInfo(
      resultUnit: json["resultUnit"],
      customerId: json['customerId'],
      bizId: json['bizId'],
      resultMode: json['resultMode'],
      bizType: json['bizType'],
      name: json['name'],
      elderName: json['elderName'],
      age: json['age'],
      id: json['id'],
      sexName: json['sexName'],
      branchName: json['branchName'],
      buildingNo: json['buildingNo'],
      floorNo: json['floorNo'],
      roomNo: json['roomNo'],
      statusSecondName: json['statusSecondName'],
      nurseLevelName: json['nurseLevelName'],
      bizParams: BizParams.fromJson(json['bizParams']),
      dateTime: DateTime.now(),
      itemRemark: "",
      isSelected: false,
    );
  }
}

class BizParams {
  String? serviceItem;
  int? examinationRecordId;
  int? launchType;
  String? sheetId;
  String? elderName;
  List<PendingInfo>? result;

  BizParams({
    this.serviceItem,
    this.launchType,
    this.examinationRecordId,
    this.result,
    this.sheetId,
    this.elderName,
    // this.undoCount,
  });

  factory BizParams.fromJson(Map<String, dynamic> json) {
    final List? originList = json['result'].runtimeType.toString() == "String"
        ? jsonDecode(json['result'])
        : json['result'];
    List<PendingInfo> protocolList = [];
    if (originList != null) {
      originList.map((value) => PendingInfo.fromJson(value)).toList();
    }
    return BizParams(
      result: protocolList,
      serviceItem: json['serviceItem'],
      launchType: json['launchType'],
      examinationRecordId: json['examinationRecordId'],
      sheetId: json['sheetId'],
      elderName: json['elderName'],
    );
  }
}
